import 'package:flutter/gestures.dart';
import 'package:flutter_elf/base/base_page_state.dart';
/// CreateTime 2020/6/28 15:13
/// CreateUser chen 
/// ProjectName flutter_elf
import 'package:flutter_elf/config/component_index.dart';

class ZhihuPage extends StatefulWidget{
  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return ZhihuViewPage();
  }
}

class ZhihuViewPage extends BasePageState{

  PageController pageController;
  ScrollPhysics physics1 = ClampingScrollPhysics(),physics2 = ClampingScrollPhysics();
  @override
  void onCreate() {
    // TODO: implement onCreate
    super.onCreate();
    key = GlobalKey();
    pageController = PageController(viewportFraction: 0.8);
    controller1 = ScrollController();
    controller2 = ScrollController();
    controller1.addListener((){
      if(controller1.offset == controller1.position.maxScrollExtent){
        print('滚动到底部了额');
        physics1 =  NeverScrollableScrollPhysics();
      }else{
        physics1 =  ClampingScrollPhysics();
      }
      setState(() {});
    });
    controller2.addListener((){
      if(controller2.offset == controller2.position.maxScrollExtent){
        print('滚动到底部了额');
        physics2 =  NeverScrollableScrollPhysics();
      }else{
        physics2 =  ClampingScrollPhysics();
      }
      setState(() {});
    });

  }
  GlobalKey key;
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(body: Container(
      height: double.infinity,
      width: double.infinity,
      child: PageView(
        key: key,
        pageSnapping: true,
        scrollDirection: Axis.vertical,
        controller: pageController,
        physics: PageScrollPhysics(),
        children: <Widget>[
          buildText1('1'),
          buildText2('2'),
        ],
        dragStartBehavior: DragStartBehavior.down,
      ),
    ));
  }


  ScrollController controller1;
  buildText1(String text){
    return ListView.builder(itemBuilder: (context,index){
      return Text('$index');
    },itemCount: 100,shrinkWrap: true,controller: controller1,physics:physics1);
  }

  ScrollController controller2;
  buildText2(String text){
    return ListView.builder(itemBuilder: (context,index){
      return Text('$index');
    },itemCount: 100,shrinkWrap: true,controller: controller2,physics: physics2,);
  }

}